package com.study.spmongodb.wwj.thread.char09;

/**
 * @author MI
 * @version 1.0
 * @date 2020/12/6 14:56
 */
public class ProduceConsumerVersion1 {

    private int i = 1;
    private final Object LOCK = new Object();

    private void produce() {
        synchronized (LOCK) {
            System.out.println("p>--" + i++);
        }
    }

    private void consume() {
        synchronized (LOCK) {
            System.out.println("c>--" + i);
        }
    }

    public static void main(String[] args) {

        final ProduceConsumerVersion1 pc = new ProduceConsumerVersion1();
        new Thread(() -> {
            while (true) {
                pc.produce();
            }
        }, "p").start();

        new Thread(() -> {
            while (true) {
                pc.consume();
            }
        }, "c").start();


    }
}
